<template>
  <view class="fund-index">
    <view class="fund-item">
        <fui-input :borderBottom="false" v-model="pingJunGongZi" label="您的月工资:" borderTop placeholder=""></fui-input>
        <view>元</view>
    </view>

    <view class="fund-item">
        <fui-input  :borderBottom="false" v-model="nianLing" label="现在年龄:" borderTop ></fui-input>
        <view>岁</view>
    </view>
    <view class="fund-item">
        <fui-input  :borderBottom="false" v-model="jiLei" label="账号积累的养老金额:" borderTop ></fui-input>
        <view>元</view>
    </view>
    <view class="fund-item">
        <fui-input  :borderBottom="false" v-model="zhiGongZenZhang" label="默认职工工资增长率:" borderTop ></fui-input>
        <view>%</view>
    </view>
    <view class="fund-item">
        <fui-input  :borderBottom="false" v-model="zhiGongGongZi" label="职工上年月平均工资:" borderTop ></fui-input>
        <view>元</view>
    </view>
    <view class="fund-item">
        <fui-input  :borderBottom="false" v-model="tuiXiu" label="您打算退休时年龄:" borderTop ></fui-input>
        <view>岁</view>
    </view>
    <view class="fund-item">
        <fui-input   :borderBottom="false" v-model="geRenZenZhang" label="默认个人工资增长率:" borderTop ></fui-input>
        <view>%</view>
    </view>
    <view class="fund-item">
        <fui-input  :borderBottom="false" v-model="qiWang" label="您期望退休后的工资:" borderTop ></fui-input>
        <view>元</view>
    </view>
    <view class="commit" :class="sizeStatus ? 'commit-small': 'commit-big'" @click="commit"> 一键查询</view>
  </view>
  <LandscapeModel v-model:show="show" :sonFun="sonFun"/>
</template>

<script setup lang="ts">
import LandscapeModel from "@/components/Landscape/LandscapeModel.vue";
import {EnumFund} from "../content";
const pingJunGongZi = ref()
const zhiGongGongZi = ref()
const nianLing = ref()
const jiLei = ref()
const zhiGongZenZhang = ref(3)
const tuiXiu = ref()
const geRenZenZhang = ref('5')
const qiWang = ref()
const yangLaoJin =  ref()
const show = ref(false)
const sizeStatus = ref(false)
const emit = defineEmits(['update:defStatus','update:yangLaoJin'])

const GetTY = ()=>{
    if (pingJunGongZi.value < zhiGongGongZi.value * 0.6) pingJunGongZi.value = zhiGongGongZi.value * 0.6;
    if (pingJunGongZi.value > zhiGongGongZi.value * 3) pingJunGongZi.value = zhiGongGongZi.value * 3;
}
const commit = ()=>{
    if(!Number(pingJunGongZi.value) || !Number(zhiGongGongZi.value)|| !Number(nianLing.value) || !Number(jiLei.value) || !Number(zhiGongZenZhang.value) 
       || !Number(tuiXiu.value)   || !Number(qiWang.value)){
        uni.showToast({
            title: '请输入数字',
            duration: 2000,
            icon:"none"
        });
        return
    }
    show.value = true
}   

const sonFun = ()=>{
    GetTY()
    var jiChu = zhiGongGongZi.value * (1 + (tuiXiu.value - nianLing.value) * zhiGongZenZhang.value / 100 )* 0.2;
    var zhangHuZongE = parseFloat(jiLei.value) + parseFloat(pingJunGongZi.value) * 0.08 * 12 * (Math.pow(1 + (parseFloat(geRenZenZhang.value) / 100), 
    parseFloat(tuiXiu.value) - parseFloat(nianLing.value)) - 1) / (parseFloat(geRenZenZhang.value) / 100);
    yangLaoJin.value = Format(jiChu + zhangHuZongE / 120)
    uni.hideLoading();
    emit('update:yangLaoJin',yangLaoJin.value)
    emit('update:defStatus',EnumFund.RESULT)
}

const Format = (myFloat:number)=>{
    return Math.round(myFloat * Math.pow(10, 2)) / Math.pow(10, 2);
}

const startTimer = () => {
  setInterval(() => {
      sizeStatus.value =  !sizeStatus.value
  }, 1000); // 每秒执行一次
};
onMounted(()=>{
  startTimer()
})


</script>

<style lang="scss" scoped>
.fund-index{
    z-index: 102;
    position: absolute;
    top: 32%;
    width: 90%;
    margin: 0 5%;
    text-align: center;
    letter-spacing: 1rpx;
    background:white;
    border-radius: 20rpx;
    height: 83%;
    .fund-item{
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10rpx 0;
        padding-right: 20rpx;
        font-size: 30rpx;
        .fui-list__item{
            display: flex;
            align-items: center;
            justify-content: center; 
            .fui-align__center{
                display: flex;
                align-items: center;
                justify-content: space-between;
                width: 80rpx;
            }
        }
 
    }
    .commit{
        width: 60%;
        margin: 50rpx auto;
        padding: 20rpx 40rpx;
        background: rgb(58,212,248);
        border-radius: 40rpx;
        color: #fff;
    }
    .commit-small{
        width: 60%;
        margin: 50rpx auto;
        transition: all 1s;
    }
    .commit-big{
        width: 62%;
        margin: 40rpx auto;
        transition: all 1s;
    }

}
</style>
